<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>银行管理系统登录</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body class="bg-light">
  <div class="container mt-5">
    <div class="row justify-content-center">
      <div class="col-md-4">
        <div class="card">
          <div class="card-header text-center">银行管理系统登录</div>
          <div class="card-body">
            <form>
              <div class="mb-3">
                <label for="username" class="form-label">用户名</label>
                <input type="text" class="form-control" id="username" required>
              </div>
              <div class="mb-3">
                <label for="password" class="form-label">密码</label>
                <input type="password" class="form-control" id="password" required>
              </div>
              <div class="mb-3">
                <label class="form-label">身份</label>
                <select class="form-select" id="role">
                  <option value="admin">管理员</option>
                  <option value="customer">客户</option>
                </select>
              </div>
              <button type="submit" class="btn btn-primary w-100">登录</button>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script>
    document.querySelector('form').onsubmit = async function(e) {
      e.preventDefault();
      const cardID = document.getElementById('username').value;
      const password = document.getElementById('password').value;
      const role = document.getElementById('role').value;
      const res = await fetch('/api/login', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ cardID, password })
      });
      const data = await res.json();
      if (data.success) {
        if (role === 'admin') {
          window.location.href = '/admin/dashboard';
        } else {
          window.location.href = '/customer/dashboard';
        }
      } else {
        alert(data.msg || '账号或密码错误');
      }
    }
  </script>
</body>
</html>